package com.example.controller;

import com.example.domain.Comment;
import com.example.domain.CultureProject;
import com.example.domain.LeaveMessage;
import com.example.domain.vo.*;
import com.example.service.CultureCommunityService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/front/culture/community")
@Slf4j
public class CultureCommunityController {
    @Autowired
    private CultureCommunityService cultureCommunityService;

    /**
     * 查询文化项目
     *
     * @param cultureProject
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping
    public Result queryCulture(CultureProject cultureProject,
                               @RequestParam(defaultValue = "1") Integer currentPage,
                               @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<CultureProject> project = cultureCommunityService.queryCulture(cultureProject, currentPage, pageSize);
        return Result.success(project);
    }

    /**
     * 查询所有文化分类以及分类对应数量
     *
     * @return
     */
    @GetMapping("/queryCultureCategory")
    public Result queryCultureCategory() {
        List<CultureProjectCategoryVo> list = cultureCommunityService.queryCultureCategory();
        return Result.success(list);
    }

    /**
     * 根据id查询文化项目
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryCultureById(@PathVariable Long id) {
        CultureProject cultureProject = cultureCommunityService.queryCultureById(id);
        return Result.success(cultureProject);
    }

    /**
     * 提交留言
     *
     * @param leaveMessage
     * @return
     */
    @PostMapping("/submit/LeaveMessage")
    public Result submitLeaveMessage(@RequestBody LeaveMessage leaveMessage) {
        cultureCommunityService.submitLeaveMessage(leaveMessage);
        return Result.success();
    }

    /**
     * 查询留言
     *
     * @param leaveMessageVo
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/query/LeaveMessage")
    public Result queryLeaveMessage(LeaveMessageVo leaveMessageVo,
                                    @RequestParam(defaultValue = "1") Integer currentPage,
                                    @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<LeaveMessageVo> leaveMessagePageInfo = cultureCommunityService.queryLeaveMessage(leaveMessageVo, currentPage, pageSize);
        return Result.success(leaveMessagePageInfo);
    }

    /**
     * 添加评论
     *
     * @param comment
     * @return
     */
    @PostMapping("/submit/comment")
    public Result addComments(@RequestBody Comment comment) {
        cultureCommunityService.addComments(comment);
        return Result.success();
    }

    /**
     * 删除评论
     *
     * @param commentId
     * @return
     */
    @DeleteMapping("/delete/comment/{commentId}")
    public Result removeComments(@PathVariable Long commentId) {
        cultureCommunityService.removeComments(commentId);
        return Result.success();
    }

    /**
     * 根据文化项目id查询评论
     *
     * @param CultureId
     * @return
     */
    @GetMapping("/query/comment")
    public Result getCommentsByCultureId(@RequestParam("CultureId") Long CultureId,
                                         @RequestParam(defaultValue = "1") Integer currentPage,
                                         @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<CommentVo> comments = cultureCommunityService.getCommentsByCultureId(CultureId, currentPage, pageSize);
        return Result.success(comments);
    }

    /**
     * 给对应评论点赞
     *
     * @param commentId
     * @return
     */
    @GetMapping("/update/likes/{commentId}/{likes}")
    public Result updateLike(@PathVariable Long commentId, @PathVariable Long likes) {
        cultureCommunityService.updateLike(commentId, likes);
        return Result.success();
    }

    /**
     * 给评论踩
     *
     * @param commentId
     * @param treader
     * @return
     */
    @GetMapping("/update/tread/{commentId}/{treader}")
    public Result updateTread(@PathVariable Long commentId, @PathVariable Long treader) {
        cultureCommunityService.updateTread(commentId, treader);
        return Result.success();
    }

    /**
     * 最多点赞评论
     *
     * @param CultureId
     * @return
     */
    @GetMapping("/query/comment/maxLikes/{CultureId}")
    public Result getCommentsMaxLikes(@PathVariable Long CultureId) {
        CommentVo commentVo = cultureCommunityService.getCommentsMaxLikes(CultureId);
        return Result.success(commentVo);
    }
}
